<?php
define('PWD',							dirname(__FILE__) . '/');
define('ROOT',						PWD);
define('CUSTOM_CFG_PATH',	ROOT . '/_tmp/');
define('IS_LOCAL',				$_SERVER['SERVER_ADDR'] == '127.0.0.1');
define('IS_DEBUG',				true);

include_once ROOT . '/../../ujn2/ujn.php';

function page_404() {
	echo '404 page';
}

function boot_func() {
	session_start();
}

function show_view($view_file, $data) {
	$tmp_path = ujn::get_cfg('tmp_path');

	require ujn::get_cfg('lib_path') . '/smarty/Smarty.class.php';
	$smarty = new Smarty();
	$smarty->compile_dir = "{$tmp_path}/templates_c/";
	// 	$smarty->cache_dir = "{$tmp_path}/cache/";
	// 	$smarty->caching = false;
	$smarty->left_delimiter = "{{";
	$smarty->right_delimiter = "}}";
	$smarty->assign($data);

	$output_static_html = ujn::get_cfg('output_static_html');
	if(empty($output_static_html)) {
		$smarty->display($view_file);
	} else{ // 当前页输出为静态文件
		$data = $smarty->fetch($view_file);
		$out_file = ujn::get_cfg('html_path') . $output_static_html;
		$dir = dirname($out_file);
		if(!is_dir($dir)) {
			mkdir($dir, 0777, 1);
		}
		$strlen = file_put_contents($out_file, $data);
		$out = $_REQUEST;
		$out['status'] = is_file($out_file) ? 1 : 0;
		
		$op = ujn::get_cfg('output_params');
		if(is_array($op) && !empty($op)) {
			foreach(ujn::get_cfg('output_params') as $k => $d) {
				$out[$k] = $d;
			}
		}
		die(json_encode($out));
	}
}

ujn::runApplication(array(
		'controllers_path'	=> ROOT . '/controller/',
		'models_path'				=> ROOT . '/model/',
		'templates_path'		=> PWD  . '/template/',
		'template_ext'			=> 'html',
		'tmp_path'					=> ROOT . '/_tmp/',
		'lib_path'					=> ROOT . '/_lib/',

		'html_path'					=> ROOT . '/_tmp/html/',
		'thumb_path'				=> ROOT . '/_tmp/thumb/',
		'music_path'				=> ROOT . '/_tmp/music/',
		'thumb_url'                                     => 'http://localhost/com.keke/newcms/_tmp/thumb/',
		
		'url' => array(
				'home' => 'http://localhost/com.keke/newcms/',
				'static' => 'http://localhost/static/',
		),
		
		'dhs' => array(
				'mysql' => array(
						'host'			=> 'localhost',
						'user'			=> 'root',
						'password'	=> '12580',
						'dbname'		=> 'keke',
				),
		)
), ( defined('RUN_FUNC') && function_exists(RUN_FUNC) ) ? RUN_FUNC : '');
